import { createApp } from 'vue'
import App from './App.vue'
import { router } from './router/index'


import axios from 'axios'
import qs from 'qs'


import Vant from 'vant';
import 'vant/lib/index.css';

import store from './store'

// 引入公共组件
import Plugins from './plugins'

import instance from 'axios'
// // 请求拦截器
instance.interceptors.request.use(function (config) {
	let token = localStorage.getItem('token')

	if (token) {
		config.headers.token = token;
	}
	return config
},
	function (err) {
		return Promise.reject(err)
	}
)


//封装请求
const myaxios = function (url, type, data = {}) {
	return new
		Promise((resolve) => {
			// 添加token
			// data['token'] = localStorage.getItem('token')
			//判断
			if (type === "get" || type === "delete") {
				axios({
					method: type,
					url: url,
					params: data
				}).then((result) => {
					resolve(result.data);
				});
			} else {
				axios({
					method: type,
					url: url,
					data: qs.stringify(data)
				}).then((result) => {
					resolve(result.data);
				});
			}
		});
}

const app = createApp(App)


app.config.globalProperties.myaxios = myaxios;
app.config.globalProperties.axios = axios;
app.config.globalProperties.upload_dir = "https://localhost/static/";
// 项目后端接口url
app.config.globalProperties.weburl = 'http://localhost:8000/';

app.use(router);
app.use(Vant);

app.use(store)
app.use(Plugins)

app.mount('#app')